package com.example.listener;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
import org.springframework.stereotype.Component;


//Consumer 限流机制
//  1. 确保 ack机制为手动确认。
//  2. prefetch = 1表示消费端每次从mq拉取一条消息来消费，直到手动确认消费完毕后，才会继续拉取下一条消息
//  3.
@Component
public class QosListener implements ChannelAwareMessageListener {
    @RabbitListener(queues = "confirm_queue")
    @Override
    public void onMessage(Message message, Channel channel) throws Exception {
            //1. 接受转换消息
            System.out.println(new String(message.getBody()));
//        2、处理业务逻辑
            System.out.println("处理业务逻辑");
//            int i =3/0;
//        3. 手动签收
//            channel.basicAck(deliveryTag,true);

    }
}
